home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / sbin / update-fonts-alias < prev    next >
Encoding:
Text File  |  2009-12-06  |  5.7 KB  |  199 lines

  1. #!/bin/sh
  2.  
  3. # $Id: update-fonts-alias 189 2005-06-11 00:04:27Z branden $
  4.  
  5. # This program compiles fonts.alias files for X font directories; see
  6. # mkfontdir(1x) for a description of the format of fonts.alias files.
  7.  
  8. # Copyright 1999, 2001, 2002, 2004 Branden Robinson.
  9. # Copyright 2006 Steve Langasek.
  10. # Licensed under the GNU General Public License, version 2.  See the file
  11. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  12.  
  13. PROGNAME=${0##*/}
  14.  
  15. # Query the terminal to establish a default number of columns to use for
  16. # displaying messages to the user.  This is used only as a fallback in the event
  17. # the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while the
  18. # script is running, and this cannot, only being calculated once.)
  19. DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true
  20. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then
  21.     DEFCOLUMNS=80
  22. fi
  23.  
  24. # Display a message, wrapping lines at the terminal width.
  25. message () {
  26.     echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS}
  27. }
  28.  
  29. # Display a warning message.
  30. warn () {
  31.     message "warning: $*" >&2
  32. }
  33.  
  34. # Display an error message and exit.
  35. die () {
  36.     message "fatal error: $*" >&2
  37.     exit 1
  38. }
  39.  
  40. # Display a usage message.
  41. usage () {
  42.     if [ -n "$*" ]; then
  43.         message "usage error: $*"
  44.     fi
  45.     cat <<EOF
  46. Usage: $PROGNAME [OPTIONS] DIRECTORY ...
  47.        $PROGNAME { -h | --help }
  48. This program combines X font alias information from several packages into a
  49. single file that is placed in each specified X font directory DIRECTORY.  This
  50. utility is primarily useful to Debian package maintainer scripts.  See
  51. update-fonts-alias(8) for more information.
  52. Options:
  53.     -h, --help                        display this usage message and exit
  54.     -i, --include ALIAS-FILE          drop ALIAS-FILE from exlude list if any
  55.     -x, --exclude ALIAS-FILE          add ALIAS-FILE to exclude list
  56. EOF
  57. }
  58.  
  59. X11R7_LAYOUT=
  60. INCLUDE_ALIAS=
  61. EXCLUDE_ALIAS=
  62. EXCLUDE_CONF=/var/lib/xfonts/excluded-aliases
  63.  
  64. # Validate options.
  65. while [ $# -gt 0 ]; do
  66.     case "$1" in
  67.         -h|--help)
  68.             usage
  69.             exit 0
  70.             ;;
  71.         -7|--x11r7-layout)
  72.             X11R7_LAYOUT=true
  73.             shift
  74.             ;;
  75.         -i|--include)
  76.             if [ $# -lt 2 ]; then
  77.                 usage "alias file to include is missing" >&2
  78.                 exit 2
  79.             fi
  80.             INCLUDE_ALIAS="$INCLUDE_ALIAS $2"
  81.             shift 2
  82.             ;;
  83.         -x|--exclude)
  84.             if [ $# -lt 2 ]; then
  85.                 usage "alias file to exclude is missing" >&2
  86.                 exit 2
  87.             fi
  88.             EXCLUDE_ALIAS="$EXCLUDE_ALIAS $2"
  89.             shift 2
  90.             ;;
  91.         -*)
  92.             usage "unrecognized option" >&2
  93.             exit 2
  94.             ;;
  95.         *)
  96.             break
  97.             ;;
  98.     esac
  99. done
  100.  
  101. if [ $# -eq 0 ]; then
  102.     usage "one or more font directories must be specified" >&2
  103.     exit 2
  104. fi
  105.  
  106. # Remove aliases to be included from exclude list
  107. for f in $INCLUDE_ALIAS; do
  108.     sed -i "\\,^$f$,d" $EXCLUDE_CONF
  109. done
  110. # Add aliases to be excluded to exclude list
  111. for f in $EXCLUDE_ALIAS; do
  112.     sed -i "\\,^$f$,d" $EXCLUDE_CONF
  113.     echo "$f" >> $EXCLUDE_CONF
  114. done
  115.  
  116. while [ -n "$1" ]; do
  117.     # Try to be clever about the argument; were we given an absolute path?
  118.     if expr "$1" : "/.*" >/dev/null 2>&1; then
  119.         # Yes; an absolute path to an X font directory was provided.
  120.         X11R7DIR=$1
  121.         ETCDIR=/etc/X11/fonts/${X11R7DIR##*/}
  122.         ETC7DIR=/etc/X11/fonts/X11R7/${X11R7DIR##*/}
  123.         if [ "$X11R7DIR" = "$ETCDIR" ] || [ "$X11R7DIR" = "$ETC7DIR" ]; then
  124.             # We were given an /etc directory as an argument.
  125.             die "path to X font directory must be used"
  126.         else
  127.             warn "absolute path $X11R7DIR was provided"
  128.         fi
  129.     else
  130.         # No; a relative path was provided -- assume we were given just the
  131.         # basename.
  132.         X11R7DIR=/usr/share/fonts/X11/$1
  133.         ETCDIR=/etc/X11/fonts/$1
  134.         ETC7DIR=/etc/X11/fonts/X11R7/$1
  135.     fi
  136.  
  137.     shift
  138.  
  139.     # Confirm that the directories to be operated on exist.
  140.     VALIDSRC=
  141.     if [ -d "$ETCDIR" ]; then
  142.         VALIDSRC=yes
  143.     else
  144.         warn "$ETCDIR does not exist or is not a directory"
  145.     fi
  146.     if [ -d "$ETC7DIR" ]; then
  147.         VALIDSRC=yes
  148.     else
  149.         if [ -n "$X11R7_LAYOUT" ]; then
  150.             warn "$ETC7DIR does not exist or is not a directory"
  151.         fi
  152.     fi
  153.  
  154.     VALIDDEST=
  155.     if [ -d "$X11R7DIR" ]; then
  156.             VALIDDEST=yes
  157.     else
  158.         warn "$X11R7DIR does not exist or is not a directory"
  159.     fi
  160.  
  161.     if [ -z "$VALIDSRC" ] || [ -z "$VALIDDEST" ]; then
  162.         continue
  163.     fi
  164.  
  165.     if [ -n "$X11R7DIR" ] && [ -d "$X11R7DIR" ]; then
  166.         # Write the new alias file in a temporary location in case we are
  167.         # interrupted.
  168.         cat >"$X11R7DIR/fonts.alias.update-new" <<EOF
  169. !! fonts.alias -- automatically generated file.  DO NOT EDIT.
  170. !! To modify, see update-fonts-alias(8).
  171. EOF
  172.         has_data=0
  173.         for FILE in "$ETCDIR"/*.alias "$ETC7DIR"/*.alias; do
  174.             [ -e "$FILE" ] || continue
  175.  
  176.             # Skip excluded aliases
  177.             grep -q "^$FILE$" $EXCLUDE_CONF && continue
  178.  
  179.             echo "!! $FILE" >>"$X11R7DIR/fonts.alias.update-new"
  180.             cat "$FILE" >>"$X11R7DIR/fonts.alias.update-new"
  181.             has_data=1
  182.         done
  183.         if [ $has_data -eq 1 ]; then
  184.           mv "$X11R7DIR/fonts.alias.update-new" "$X11R7DIR/fonts.alias"
  185.         else
  186.           rm -f "$X11R7DIR/fonts.alias.update-new"
  187.           # There are no files to process; remove any alias file already in
  188.           # the font directory.
  189.           rm -f "$X11R7DIR/fonts.alias"
  190.           # Remove the font directory if it is empty.
  191.           rmdir "$X11R7DIR" >/dev/null 2>&1 || true
  192.         fi
  193.     fi
  194. done
  195.  
  196. exit 0
  197.  
  198. # vim:set ai et sts=4 sw=4 tw=80:
  199.